package ch.jamme.reference;

import org.jdom.*;

/**
 * It holds the reference to an xml marshallable object by binding the object itself to its xml representation.
 * It is used to split an xml tree in many subtrees, allowing the parallelization of a marshall process.
 * @author Mario Fusco
 */
public class XmlMarshallableReference {

	private Element parentElement;
	private Object value;
	
	public XmlMarshallableReference(Element parentElement, Object value) {
		this.parentElement = parentElement;
		this.value = value;
	}
	
	public Element getParentElement() {
		return parentElement;
	}
	
	public Object getValue() {
		return value;
	}
	
	public boolean isVoid() {
		return parentElement == null;
	}
	
	public static XmlMarshallableReference createVoidReference() {
		return new XmlMarshallableReference(null, null);
	}
	
	@Override
	public String toString() {
		if (isVoid()) return "Void reference";
		return "Element " + parentElement.getName() + " is reference of " + value;
	}
}
